package cn.hsw.platform.core.api;

import cn.hsw.platform.core.dto.ResultDto;
import cn.hsw.platform.core.enums.HttpEnum;
import cn.hsw.platform.core.util.ResultUtil;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * hsw-snow-flake-id 项目调用
 * @author 李子木
 * @date 2020-11-05
 */
@Component
@FeignClient(name = "hsw-snow-flake-id",fallbackFactory = SnowFlakeApi.AuthServerApiFallbackFactory.class)
public interface SnowFlakeApi  {
    /**
     * 获取ID主键
     * @return ID
     */
    @RequestMapping(path = "/generate", method = RequestMethod.POST)
    ResultDto<Long> generate();

    @Component
    class AuthServerApiFallbackFactory implements FallbackFactory<SnowFlakeApi> {

        @Override
        public SnowFlakeApi create(Throwable throwable) {
            return () -> ResultUtil.error(HttpEnum.ID_GENERA_RPC_ERROR);
        }
    }
}
